/*************************************************************************
	> File Name: P1451.cpp
	> Author: yufangze
	> Mail: 2224590123@qq.com
	> Created Time: 2024-12-16 16:27:34
 ************************************************************************/

#include <iostream>
#include <string>
using namespace std;

#define MAX_N 100
int grid[MAX_N + 5][MAX_N + 5];
int visit[MAX_N + 5][MAX_N + 5];
int dir[4][2] = {
    {-1, 0}, {1, 0}, {0, -1}, {0, 1}
};

int n, m;

void dfs(int i, int j) {
    visit[i][j] = 1;
    for (int k = 0; k < 4; k++) {
        int x = i + dir[k][0];
        int y = j + dir[k][1];
        if (x < 0 || x >= n || y < 0 || y >= m) continue;
        if (grid[x][y] == 0 || visit[x][y] == 1) continue;
        dfs(x, y);
    }
    return ;
}

int main() {
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        string str;
        cin >> str;
        for (int j = 0; j < str.size(); j++) {
            grid[i][j] = str[j] - '0';
        }
    }
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (grid[i][j] == 0 || visit[i][j] == 1) continue;
            dfs(i, j);
            cnt += 1;
        }
    }
    cout << cnt << endl;
    return 0;
}
